<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<link type="text/css" rel="stylesheet"
	href="<%=request.getContextPath()%>/styles/global.css" />
<link type="text/css" rel="stylesheet"
	href="<%=request.getContextPath()%>/styles/global_color.css" />
<title>My JSP 'service_list.jsp' starting page</title>
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
<script language="javascript" type="text/javascript">
	//排序按钮的点击事件
	function sort(btnObj) {
		if (btnObj.className == "sort_desc"){
			btnObj.className = "sort_asc";
			if(btnObj.value="月租"){
				$.ajax({
					url:"${pageContext.request.contextPath}/fee/sort",
					data:"column=base_cost&flag=desc&currPage=" + $("#currPage").val() + "&pageSize=" + $("#pageSize").val(),
					type:"post",
					datatype:"json",
					success:function(data){
						//进行ajax返回的数据处理
						var datas = eval(data);
						ajaxData(datas);
					},
					async:false
				});	
			}
			
			
		}else{
			btnObj.className = "sort_desc";
			if(btnObj.value="月租"){
				$.ajax({
					url:"${pageContext.request.contextPath}/fee/sort",
					data:"column=base_cost&flag=asc&currPage=" + $("#currPage").val() + "&pageSize=" + $("#pageSize").val(),
					type:"post",
					datatype:"json",
					success:function(data){
						//进行ajax返回的数据处理
						var datas = eval(data);
						ajaxData(datas);
					},
					async:false
				});	
			}
		}
		
	}

	//进行ajax返回的数据处理
 	function ajaxData(data){
		$("#datalist").empty();
		console.log(data);
		console.log(data.length);
		data1 = "<tr>"
			+"<th>资费ID</th>"
			+"<th class='width100'>资费名称</th>"
			+"<th>基本时长</th>"
			+"<th>基本费用</th>"
			+"<th>单位费用</th>"
			+"<th>创建时间</th>"
			+"<th>开通时间</th>"
			+"<th class='width:50'>状态</th>"
			+"<th class='width:200'></th>"
			+"</tr>";
				for(i=0; i<data.length; i++){
				data1 += "<tr>"
					+"<td>" + data[i].costId
					+"</td><td><a href='${pageContext.request.contextPath}/fee/toDetailJsp?costId='" + data[i].costId + ">" + data[i].name + "</a>"
					+"</td><td>" + data[i].baseDuration
					+"</td><td>" + data[i].baseCost
					+"</td><td>" + data[i].unitCost
					+"</td><td>" + data[i].creatTime
					+"</td><td>" + data[i].startTime
					+"</td><td class='width:50'>";
					if(data[i].status == 0){
						data1 += "开通"+"</td><td class='width:200'>" ;
					} else {
						data1 += "暂停"+"</td><td class='width:200'>" ;
					}
					if(data[i].status != 0){
						data1 += "<input type='button' value='启用' class='btn_start'" +
							" onClick='startFee("+data[i].costId + ");' />" +
							"<input type='button' value='修改' class='btn_modify'" +
								" onClick='location.href=\"fee_modi.html\";' />"+
							"<input type='button' value='删除' class='btn_delete'" +
								" onClick='deleteFee(" + data[i].costId + ");' />"
							+"</td></tr>";	
					} else {
						data1 += "</td></tr>";
					}		
			}	
				console.log(data1);
				$("#datalist").html(data1);
	} 
	
	
	//启用
	function startFee(costId) {
		var r = window.confirm("确定要启用此资费吗？资费启用后将不能修改和删除。");
		if(r){
			$.ajax({
				url:"${pageContext.request.contextPath}/fee/updStatus?costId=" + costId,
				type:"GET",
				datatype:"text",
				success:function(data){
					//进行ajax返回的数据处理
					if(data.trim()=="OK"){
						$("#operate_result_info").html("资费开通成功！");
						document.getElementById("operate_result_info").style.display = "block";
						//提示3秒后跳转查询
				    	window.setTimeout("location.href='${pageContext.request.contextPath}/fee/list'", 3000);					
					}
				},
				async:false
			});
		}
		
	}
	//删除
	function deleteFee(costId) {
		var r = window.confirm("确定要删除此资费吗？");
		if(r){
			$.ajax({
				url:"${pageContext.request.contextPath}/fee/del?costId=" + costId,
				type:"GET",
				datatype:"text",
				success:function(data){
					//进行ajax返回的数据处理
					if(data.trim()=="OK"){
						document.getElementById("operate_result_info").style.display = "block";
						//提示3秒后跳转查询
				    	window.setTimeout("location.href='${pageContext.request.contextPath}/fee/list'", 3000);					
					}
				},
				async:false
			});
		}		
	}
</script>
</head>

<body>

	<div id="header">
		<img src="<%=path %>/images/logo.png" alt="logo" class="left" /> <a href="#">[退出]</a>
	</div>


	<div id="navi">
		<%@include file="/jsp/commen/menu.jsp"%>
	</div>


	<div id="main">
		<form id="serachForm"
			action="${pageContext.request.contextPath}/fee/list">

			<div class="search_add">
				<!-- 隐藏框 隐藏附带当前页码和每页条数 -->
				<input type="hidden" name="currPage" id="currPage" /> 
				<input type="hidden" name="pageSize" id="pageSize" />
				<div>
					<input type="button" value="月租" class="sort_asc" onClick="sort(this);" /> 
					<input type="button" value="基费" class="sort_asc" onClick="sort(this);" /> 
					<input type="button" value="时长" class="sort_asc" onClick="sort(this);" />
				</div>
				<input type="button" value="增加" class="btn_add"
					onClick="location.href='${pageContext.request.contextPath}/jsp/fee/toAdd'" />
			</div>

			<div id="operate_result_info" class="operate_success">
				<img src="<%=path %>/images/close.png"
					onClick="this.parentNode.style.display='none';" /> 删除成功！
			</div>
			
			<div id="data">
				<table id="datalist">
					<tr>
						<th>资费ID</th>
						<th class="width100">资费名称</th>
						<th>基本时长</th>
						<th>基本费用</th>
						<th>单位费用</th>
						<th>创建时间</th>
						<th>开通时间</th>
						<th class="width50">状态</th>
						<th class="width200"></th>
					</tr>
					<c:forEach items="${page.list }" var="feeInfo">
					<tr>
						<td>${feeInfo.costId }</td>
						<td><a href="${pageContext.request.contextPath}/fee/toDetailJsp?costId=${feeInfo.costId }" >${feeInfo.name }</a></td>
						<td>${feeInfo.baseDuration }</td>
						<td>${feeInfo.baseCost }</td>
						<td>${feeInfo.unitCost }</td>
						<td>${feeInfo.creatTime }</td>
						<td>${feeInfo.startTime }</td>
						<td>
							<c:if test="${feeInfo.status == 0 }">开通</c:if>
							<c:if test="${feeInfo.status == 1 }">暂停</c:if>
						</td>
						<td>
							<c:if test="${feeInfo.status != 0 }">
								<input type="button" value="启用" class="btn_start"
									onClick="startFee(${feeInfo.costId });" /> 
								<input type="button" value="修改" class="btn_modify"
									onClick="location.href='fee_modi.html'/*tpa=http://demo.mycodes.net/houtai/isoakJavaDemoSystem/fee/fee_modi.html*/;" />
								<input type="button" value="删除" class="btn_delete"
									onClick="deleteFee(${feeInfo.costId });" />
							</c:if>
						</td>
					</tr>
				</c:forEach>
				</table>
				<p>
					业务说明：<br /> 1、创建资费时，状态为暂停，记载创建时间；<br /> 2、暂停状态下，可修改，可删除；<br />
					3、开通后，记载开通时间，且开通后不能修改、不能再停用、也不能删除；<br />
					4、业务账号修改资费时，在下月底统一触发，修改其关联的资费ID（此触发动作由程序处理）
				</p>
			</div>

			<div id="pages">
				<%@include file="/jsp/commen/page.jsp"%>
			</div>
		</form>
	</div>

	<div id="footer">
		<p>[源自橡树的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
		<p>版权所有(C)橡树信息科技有限公司</p>
	</div>
</body>
</html>
